//
//  HNSH_ChatReceiveRedHeader.m
//  NongYe
//
//  Created by 李宇廷 on 2023/2/6.
//

#import "HNSH_ChatReceiveRedHeader.h"

@interface HNSH_ChatReceiveRedHeader ()

/* imgV */
@property (nonatomic, strong) UIImageView *imgV;
/* nameLabel */
@property (nonatomic, strong) UILabel *nameLabel;
/* moneyLabel */
@property (nonatomic, strong) UILabel *moneyLabel;
/* lineView */
@property (nonatomic, strong) UIView *lineView;

@end

@implementation HNSH_ChatReceiveRedHeader

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}

- (void)setModel:(NYChatRedInfoModel *)model {
    _model = model;
    self.nameLabel.text = model.title;
    self.moneyLabel.text = [NSString stringWithFormat:@"%@ %@",model.amount,model.capital_text];
    self.moneyLabel.attributedText = [ST_AttributeLabelTool handleLabelWithContent:self.moneyLabel.text SelectContent:model.capital_text CommonFont:self.moneyLabel.font SpeFont:[UIFont systemFontOfSize:16] Color:self.moneyLabel.textColor];
    [self.imgV sd_setImageWithURL:[NSURL URLWithString:model.avatar_url] placeholderImage:[UIImage imageNamed:@"login_home_center_icon"]];
}

- (void)addAllViews {
    [self addSubview:self.imgV];
    [self addSubview:self.nameLabel];
    [self addSubview:self.moneyLabel];
    [self addSubview:self.lineView];
}

- (void)addAllLayout {
    [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(36);
        make.centerX.equalTo(self.mas_centerX);
        make.width.height.mas_equalTo(60);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.imgV.mas_bottom).offset(12);
        make.centerX.equalTo(self.mas_centerX);
        make.height.mas_equalTo(22);
    }];
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nameLabel.mas_bottom).offset(20);
        make.centerX.equalTo(self.mas_centerX);
        make.height.mas_equalTo(50);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.height.mas_equalTo(8);
    }];
}


#pragma mark lazy
- (UIImageView *)imgV {
    if (!_imgV) {
        _imgV = [[UIImageView alloc]init];
        _imgV.layer.cornerRadius = 4.0f;
        _imgV.layer.masksToBounds = YES;
    }
    return _imgV;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.textColor = [UIColor colorWithHexString:@"#333333"];
        _nameLabel.font = [UIFont systemFontOfSize:16];
    }
    return _nameLabel;
}

- (UILabel *)moneyLabel {
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc]init];
        _moneyLabel.textColor = [UIColor colorWithHexString:@"#DF7302"];
        _moneyLabel.font = [UIFont boldSystemFontOfSize:36];
    }
    return _moneyLabel;
}

- (UIView *)lineView {
    if (!_lineView ) {
        _lineView = [[UIView alloc]init];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#F7F7F7"];
    }
    return _lineView;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
